<template>
  <div class="stockMasterTaskDetail">
    <div class="tableBox">
      <el-table
              highlight-current-row
              :data="lossList"
              :row-key="getRowKeys"
              height="calc(100% - 50px)"
              :expand-row-keys="expands"
              @expand-change="onChange"
              style="width: 100%">
        <el-table-column
                fixed="left"
                type="expand"
                label="展开"
                width="80">
          <template slot-scope="props">
            <div style="">
            <el-table
                    highlight-current-row
                    :data="goodList"
                    style="width: 96%;margin-left: 2%"
                    >
              <el-table-column
                      prop="contCode"
                      label="容器编码"
              ></el-table-column>
              <el-table-column
                      prop="cellCode"
                      label="货位编码"
              >
              </el-table-column>
              <el-table-column
                      show-overflow-tooltip
                      prop="itemCode"
                      label="物料编码"
              >
                <template slot-scope="scope">
                        <span class="textBtn"
                              @click="$parent.showPublicModal(scope.row.itemCode, 'item')">{{scope.row.itemCode}}</span>
                </template>
              </el-table-column>
              <el-table-column
                      prop="itemName"
                      label="物料名称"
              >
                <template slot-scope="scope">
                        <span class="textBtn"
                              @click="$parent.showPublicModal(scope.row.itemCode, 'item')">{{scope.row.itemName}}</span>
                </template>
              </el-table-column>
              <el-table-column
                      prop="itemPc"
                      label="物料批次"

              ></el-table-column>
              <el-table-column
                      label="出库量"
              >
                <template slot-scope="scope">
                  <div>{{scope.row.residualQuantity * -1}}</div>
                </template>
              </el-table-column>

            </el-table>
            </div>
          </template>
        </el-table-column>
        <el-table-column
                fixed="left"
                prop="profitLossCode"
                label="盘亏出库单号"
        >
        </el-table-column>
        <!---->
        <el-table-column
                prop="stockMasterCode"
                label="盘点任务号"
        >
        </el-table-column>
        <el-table-column
                prop="createUserName"
                label="创建人"
        >
        </el-table-column>
        <el-table-column
                prop="createTime"
                label="创建时间"
        >
        </el-table-column>
      </el-table>
      <el-pagination
              style="text-align: right"
              class="pagination-bottom"
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
              :page-sizes="[10, 20, 30, 50]"
              :current-page.sync="searchData.pageNum"
              :page-size="searchData.pageSize"
              layout="sizes, total, prev, pager, next, jumper"
              :total="searchData.total"
      >
      </el-pagination>
    </div>

  </div>
</template>

<script>
  import {mapState} from 'vuex'


  export default {
    name: 'Loss',
    components: {

    },
    data() {
      return {
        getRowKeys(row) {
          return row.id;
        },
        expands: [],
        isMoreSearch: false,
        isMoreSearchMaster: true,
        isMoreSearch2: false,
        activeName: 'first',

        searchData: {
          pageNum: 1,
          pageSize: 10,
          profitOrLoss: -1,
          wareId: PF.getLocal("wareId", "number"),
        },
        stockTakeMaster: {},
        lossList: [],
        goodList:[],

        searchDataItem: {
          pageNum: 1,
          pageSize: 10,
          total: null,
          keyWords: '',
          wareId: null,
          organizationId: null,
        },

        asnMaster: {},
        asnDetails: [],
        form: {
          asnMaster: {},
          asnDetails: [],
        },
        asnUdfHs: [],
        asnUdfDs: [],
        asnTypes: [],
        ids: [],
        items: [],
        suppliers: [],
        organizations: [],
        platforms: [],
        carriers: [],
        multipleSelection: [],
        qcUdfHs: [],
        qcUdfDs: [],

        innerVisibleItem: false,
        dialogNewVisible: false,
        dialogQcVisible: false,
        dialogReviewVisible: false,

        rules: {
          supplierId: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          buyType: [
            {required: true, message: '请选择供应商', trigger: 'blur'}
          ],
        },

        formLabelWidth: '120px',

        formQc: {
          billSource: 0,
          insertType: -2,
          qcMaster: {},
          qcDetails: [],
        },
        rulesQc: {
          asnBillNo: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          organizationId: [
            {required: true, message: '请选择供应商', trigger: 'blur'}
          ],
          supplierId: [
            {required: true, message: '请选择货主', trigger: 'blur'}
          ],
          memo: [
            {required: true, message: '请输入备注', trigger: 'blur'}
          ],
        },
        formReview: {
          billNo: this.$route.params.billNo,
          reviewResult: null,
          caseDetailId: null,
          memo: '',
        },
        rulesReview: {
          memo: [
            {required: true, message: '请填写审核原因', trigger: 'blur'}
          ],
        },

      }
    },
    computed: {
      ...mapState([
        "abcLevels",
        "stockTaskMasterType",
        "stockTaskMasterState",
        "stockTaskMasterOrder",
        "stockTaskDetailType",
        "stockTaskDetailState",
      ]),
      supplierId() {
        return this.form.asnMaster.supplierId
      },
    },
    watch: {
      supplierId(val) {
        for (let i = 0; i < this.suppliers.length; i++) {
          if (this.suppliers[i].supplierId === val) {
            this.form.asnMaster.supplierName = this.suppliers[i].supplierName;
          }
        }
      },
    },
    created() {
      this.getProfitList();
    },
    methods: {
      //根据盘点任务号查询盘盈入库详情
      onChange(item,expandedRows ){
        console.log("item:",item)
        console.log("expandedRows:",expandedRows)
        if (expandedRows.length){
          this.expands = [];
          this.expands.push(item.id);
          IOT.getServerData('/stock/take/log/findProfitOrLossList', 'get', {wareId:this.searchData.wareId,
            stockMasterCode:item.stockMasterCode,profitOrLoss:-1}, (ret) => {
            console.log("查询盘盈入库详情返回：",ret)
            if (ret.code === 200) {
              this.goodList = ret.rows
              /*this.searchData.total = ret.total
              this.searchData.pageNum = ret.pageNum*/
            } else {
              IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
            }
          });
        }
      },
      //查询盘盈入库单
      getProfitList() {
        IOT.getServerData("/stock/profit/loss/findByProfitLoss", 'get', this.searchData, (ret) => {
          console.log("查询盘盈入库单返回：",ret)
          if (ret.code === 200) {
            this.lossList = ret.rows;
            this.searchData.total = ret.total;
            this.searchData.pageNum = ret.pageNumber
          } else {
            IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
          }
        });
      },

      handleCurrentChange(val) {
        this.pageNum = val;
        this.getStockTakeDetailData()
      },
      handleSizeChange(val) {
        this.searchData.pageSize = val;
        this.getStockTakeDetailData();
      },
      clearSearchSelectItem() {
        this.searchDataItem.keyWords = '';
        this.searchDataItem.wareId = null;
        this.searchDataItem.organizationId = null;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      resetForm(formName) { // 重置
        this.$refs[formName].resetFields();
      },

    },
    mounted() {
    }
  }
</script>

<style scoped lang="less">
  .asnBillDetail {
  }
</style>
